package com.xqx.anno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author：xingquanxiang createTime：2019/10/2 18:57
 * description:
 */
@Component("myAspect")
//标注当前MyAspect是一个切面类
@Aspect
public class MyAspect {
    //定义切点表达式
    @Pointcut("execution(public void com.xqx.anno.*.*(..))")
    public void pointcut(){}

    //配置前置通知
    // @Before("execution(public void com.xqx.anno.*.*(..))")
    public void before(){
        System.out.println("前置增强。。。。");
    }

    public void afterReturning(){
        System.out.println("后置增强。。。。");
    }

    //ProceedingJoinPoint 正在执行的连接点
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("环绕前增强。。。。。");
        //切点方法
        Object proceed = pjp.proceed();
        System.out.println("环绕后增强。。。。。");
        return proceed;
    }

    public void afterThrowing(){
        System.out.println("抛出异常增强。。。");
    }

    @After("MyAspect.pointcut()")
    public void after(){
        System.out.println("最终增强。。。。");
    }

}
